{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"丛政村\", \"解垴村\"\n"
     ]
    }
   ],
   "source": [
    "import arcpy\n",
    "\n",
    "# 获取当前工程\n",
    "aprx = arcpy.mp.ArcGISProject(\"CURRENT\")\n",
    "\n",
    "# 获取活动的地图或场景\n",
    "active_map_or_scene = aprx.activeMap\n",
    "# 查找对应名称的图层\n",
    "layer_array = [\"梅川镇_要修改\", \"梅川镇_构筑物\"]\n",
    "des_field_name = \"sqjcwhmc\"\n",
    " \n",
    "# 初始化一个列表用于存储找到的图层\n",
    "search_layer = []\n",
    "for lyr in active_map_or_scene.listLayers():\n",
    "    for layer_name in layer_array:      \n",
    "        if lyr.name == layer_name:\n",
    "            search_layer.append(lyr)\n",
    "            break\n",
    "        \n",
    "if len(search_layer) == 0 or len(search_layer) != len(search_layer):\n",
    "    # 获取layer_array相对于search_layer的差集，并打印\n",
    "    missing_layers = set(layer_array) - {lyr.name for lyr in search_layer}\n",
    "    if missing_layers:\n",
    "        print(f\"以下图层未找到: {', '.join(missing_layers)}\")\n",
    "        exit()\n",
    "    \n",
    "\n",
    "# 初始化集合用于存储唯一值\n",
    "values_layer_list = []\n",
    "\n",
    "# 获取每个图层的唯一值集合, 无法准确获取 ???\n",
    "for current_layer in search_layer:    \n",
    "    with arcpy.da.SearchCursor(current_layer, [des_field_name]) as cursor:\n",
    "        for row in cursor:\n",
    "            if row[0]:  # 检查是否为空值\n",
    "                values_layer_list.append(row[0])\n",
    "\n",
    "# 打印合并后的唯一值，格式为 \"下屋郭村\",\"洋西港村\"\n",
    "unique_values_layer = set(values_layer_list)\n",
    "formatted_values = ', '.join(f'\"{value}\"' for value in sorted(unique_values_layer))\n",
    "print(formatted_values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ArcGISPro",
   "language": "Python",
   "name": "python3"
  },
  "language_info": {
   "file_extension": ".py",
   "name": "python",
   "version": "3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
